package com.ruoyi.keep.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.constant.Result;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.keep.domain.CommonUsers;
import com.ruoyi.keep.service.ICommonUsersService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 普通用户管理Controller
 * 
 * @author xjl
 * @date 2024-08-13
 */
@RestController
@RequestMapping("/keep/commonUsers")
public class CommonUsersController extends BaseController
{
    @Autowired
    private ICommonUsersService commonUsersService;

    /**
     * 查询普通用户管理列表
     */
    @PreAuthorize("@ss.hasPermi('keep:commonUsers:list')")
    @GetMapping("/list")
    public TableDataInfo list(CommonUsers commonUsers)
    {
        startPage();
        List<CommonUsers> list = commonUsersService.selectCommonUsersList(commonUsers);
        return getDataTable(list);
    }

    /**
     * 导出普通用户管理列表
     */
    @PreAuthorize("@ss.hasPermi('keep:commonUsers:export')")
    @Log(title = "普通用户管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CommonUsers commonUsers)
    {
        List<CommonUsers> list = commonUsersService.selectCommonUsersList(commonUsers);
        ExcelUtil<CommonUsers> util = new ExcelUtil<CommonUsers>(CommonUsers.class);
        util.exportExcel(response, list, "普通用户管理数据");
    }

    /**
     * 获取普通用户管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('keep:commonUsers:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(commonUsersService.selectCommonUsersById(id));
    }

    /**
     * 新增普通用户管理
     */
    @PreAuthorize("@ss.hasPermi('keep:commonUsers:add')")
    @Log(title = "普通用户管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CommonUsers commonUsers)
    {
        return toAjax(commonUsersService.insertCommonUsers(commonUsers));
    }

    /**
     * 修改普通用户管理
     */
    @PreAuthorize("@ss.hasPermi('keep:commonUsers:edit')")
    @Log(title = "普通用户管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CommonUsers commonUsers)
    {
        return toAjax(commonUsersService.updateCommonUsers(commonUsers));
    }

    /**
     * 删除普通用户管理
     */
    @PreAuthorize("@ss.hasPermi('keep:commonUsers:remove')")
    @Log(title = "普通用户管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(commonUsersService.deleteCommonUsersByIds(ids));
    }


    @GetMapping("/userinfo/{id}")
    public Result findInfo(@PathVariable("id") Integer id){
        List<CommonUsers> list = commonUsersService.selectCommonUsersInfoByUserId(id);
        return Result.success(list);
    }
    @GetMapping("/userCard/{id}")
    public Result findCard(@PathVariable("id") Integer id){
        List<CommonUsers> list = commonUsersService.selectCardById(id);
        return Result.success(list);
    }
    @GetMapping("/userAddress/{id}")
    public Result findAddress(@PathVariable("id") Integer id){
        List<CommonUsers> list = commonUsersService.selectAddressById(id);
        return Result.success(list);
    }

    @GetMapping("/userOrder/{id}")
    public Result findOrder(@PathVariable("id") Integer id){
        System.out.println(commonUsersService.selectOrderById(id));
        return Result.success(commonUsersService.selectOrderById(id));
    }

    @GetMapping("/userMoney/{id}")
    public Result findMoney(@PathVariable("id") Integer id){
        List<CommonUsers> list = commonUsersService.selectOrderMoneyById(id);
        return Result.success(list);
    }
}
